M=1000000;
A=0.5.*rand(3,M);
a1=sqrt(sum(A.*A))<0.5; %找出落在球内的点的位置
A(1,:)=A(1,:).*a1;  %去掉代表球外的点
A(2,:)=A(2,:).*a1;
a2=sqrt(A(1,:).^2+A(2,:).^2)>0.3;    %找出落在柱体外的点
N=sum(a2); %计算体积
V=N/M